var text = [{
  title: '详情', endTime: '申请截止时间', reward: '报酬', deadline: '任务截止期限',
  time: '申请时间', apply: '申请', cancel: '取消', report: '结题\n报告', finish: '结题',
  submit: '已提交', back: '返回', del: '删除\n项目', sending: '正在处理', phone: '联系方式：',
  finish: '已结题', evaluate: '待评价', evaluated: '已评价' 
}, {
  title: '详情', endTime: '申请截止时间', reward: '报酬', deadline: '任务截止期限',
  time: '申请时间', apply: '申请', cancel: '取消', report: '结题\n报告', finish: '结题',
  submit: '已提交', back: '返回', del: '删除\n项目', sending: '正在处理', phone: '联系方式：',
  finish: '已结题', evaluate: '待评价', evaluated: '已评价' 
}],
modal = [{
  del: '删除项目记录', del0: '删除后项目记录将不能恢复', del2: '删除', del3: '删除成功',
  eva: '未评价项目', eva0: '您还未对本项目及其完成状况做出评价噢', eva1: '以后再说', eva2: '前往'
}, {
  del: '删除项目记录', del0: '删除后项目记录将不能恢复', del2: '删除', del3: '删除成功',
  eva: '未评价项目', eva0: '您还未对本项目及其完成状况做出评价噢', eva1: '以后再说', eva2: '前往'
}];
var animating, sending, item, isPublisher = 0;
Page({

  data: {
    showMask: true,
    evaluate: false,  // 是否完成评价
  },

  onLoad: function (options) {
    sending = animating = 0;
    item = JSON.parse(decodeURIComponent(options.content));
    isPublisher = options.tab;      // 判断是任务发布者还是任务接收者
    
    if (options.tab == 1 && item.status == 8 || options.tab == 0 && item.itemInfo.status == 11) {
      this.setData({ evaluate: true });
      wx.modal(modal[wx.lang].eva, modal[wx.lang].eva0,
      modal[wx.lang].eva1, modal[wx.lang].eva2,
      null, null, () => {
        this.evaluate(); // 自动弹出评价框
      })
    }
    this.setData({
      item: item,
      text: text[wx.lang],
      theme: wx.theme,
    });
  },

  onShow() {
    if (wx.appData.refreshTab) {
      wx.appData.refreshTab = null;
      this.setData({ evaluate: false });
    }
    wx.onShow(this, text[wx.lang].title, wx.theme);
  },
  
  checkApplication() {
    let string = JSON.stringify(this.data.item.submitInfo),
      id = this.data.item.itemInfo.idpracticeitem;
    wx.onHide(this, `../report/report?id=${id}&content=${encodeURIComponent(string)}`);
  },
  
  call(e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.id,
    })
  },

  evaluate() {
    let params = `?idPractice=${item.idpractice}&evaluate=${isPublisher}`;
    wx.onHide(this, `../evaluate/evaluate` + params);
  },
  
  onShareAppMessage: function () {
    return wx.onShareAppMessage();
  }
})